#include <stdio.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/stat.h>

int main(int argc, char const* argv[])
{
    DIR *dp;
    int fd;

    dp = opendir("/");
    fd = open("file", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);

    printf("dir 's CLOSE_ON_EXEC is %s", fcntl(dirfd(dp), F_GETFD, 0)?"set\n":"unset\n");
    printf("file's CLOSE_ON_EXEC is %s", fcntl(fd, F_GETFD, 0)?"set\n":"unset\n");

    return 0;
}
